<template>
    <div class="mainDiv" style="padding: 10px;box-sizing: border-box;">
        <el-input placeholder="请输入权限等级（要求输入大于0的数字）" v-model="gradeid" style="margin: 5px 0">
            <template slot="prepend">权限等级</template>
        </el-input>
        <el-input type="textarea" placeholder="请输入对该权限的描述" v-model="remarks" style="margin: 5px 0"></el-input>
        <el-row style="margin: 5px 0">
            <el-col :span="12">
                <el-button @click.native="close" style="width:90%;display:block;">取消</el-button>
            </el-col>
            <el-col :span="12">
                <el-button type="success" @click.native="callSubmit" style="width:90%;display:block;" :loading="loading">确定</el-button>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import C from '#/src/common/common.js'
export default {
    name: 'otherpermission',
    data() {
        return {
            id: 0,
            gradeid: '',
            remarks: '',
            loading: false
        }
    },
    async mounted() {
        let RequestUrl = C.getDatas()
        if (RequestUrl.row) {
            let row = RequestUrl.row
            this.id = row.id
            this.gradeid = row.gradeid
            this.remarks = row.remarks
        }
    },
    methods: {
        async callSubmit(index) {
            if (!/^[1-9]\d*$/.test(this.gradeid)) {
                C.error('请填写要添加的权限等级！')
                return false
            }
            if (this.remarks == '') {
                C.error('请填写该权限描述！')
                return false
            }
            var data = {
                id: this.id,
                gradeid: this.gradeid,
                remarks: this.remarks
            }
            this.loading = true
            let res = await C.ajax('/organization/rule/addotherpermission', data, 'post')
            this.loading = false
            if (res) {
                C.closeBrowserWindow(res)
            }
        },
        close() {
            C.closewin()
        }
    }
}
</script>